package com.dower.clothing.controller;

import java.util.List;

import com.dower.common.annotation.Log;
import com.dower.common.core.controller.BaseController;
import com.dower.common.core.domain.AjaxResult;
import com.dower.common.core.page.TableDataInfo;
import com.dower.common.enums.BusinessType;
import com.dower.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dower.clothing.domain.ClothingType;
import com.dower.clothing.service.IClothingTypeService;

/**
 * 服装类型字典Controller
 * 
 * @author dower
 * @date 2020-08-26
 */
@Controller
@RequestMapping("/clothing/type")
public class ClothingTypeController extends BaseController
{
    private String prefix = "clothing/type";

    @Autowired
    private IClothingTypeService clothingTypeService;

    @RequiresPermissions("clothing:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询服装类型字典列表
     */
    @RequiresPermissions("clothing:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClothingType clothingType)
    {
        startPage();
        List<ClothingType> list = clothingTypeService.selectClothingTypeList(clothingType);
        return getDataTable(list);
    }

    /**
     * 导出服装类型字典列表
     */
    @RequiresPermissions("clothing:type:export")
    @Log(title = "服装类型字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClothingType clothingType)
    {
        List<ClothingType> list = clothingTypeService.selectClothingTypeList(clothingType);
        ExcelUtil<ClothingType> util = new ExcelUtil<ClothingType>(ClothingType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增服装类型字典
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服装类型字典
     */
    @RequiresPermissions("clothing:type:add")
    @Log(title = "服装类型字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClothingType clothingType)
    {
        return toAjax(clothingTypeService.insertClothingType(clothingType));
    }

    /**
     * 修改服装类型字典
     */
    @GetMapping("/edit/{numId}")
    public String edit(@PathVariable("numId") Long numId, ModelMap mmap)
    {
        ClothingType clothingType = clothingTypeService.selectClothingTypeById(numId);
        mmap.put("clothingType", clothingType);
        return prefix + "/edit";
    }

    /**
     * 修改保存服装类型字典
     */
    @RequiresPermissions("clothing:type:edit")
    @Log(title = "服装类型字典", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClothingType clothingType)
    {
        return toAjax(clothingTypeService.updateClothingType(clothingType));
    }

    /**
     * 删除服装类型字典
     */
    @RequiresPermissions("clothing:type:remove")
    @Log(title = "服装类型字典", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clothingTypeService.deleteClothingTypeByIds(ids));
    }
}
